package com.gzhuxj201.service.Impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.gzhuxj201.entity.PageBean;
import com.gzhuxj201.entity.Teacher;
import com.gzhuxj201.mapper.TeacherMapper;
import com.gzhuxj201.service.TeacherService;
import org.apache.ibatis.annotations.Select;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class TeacherServiceImpl implements TeacherService {
    @Autowired
    private TeacherMapper teacherMapper;


    @Override
    public PageBean page(int page, int pageSize,String tno, String username, Short gender) {

        PageHelper.startPage(page,pageSize);
        List<Teacher> teacherList = teacherMapper.page(tno, username,gender);

        Page<Teacher> p=(Page<Teacher>)teacherList;
        PageBean pageBean = new PageBean(p.getTotal(), p.getResult());
        return pageBean;
    }

    @Override
    public void add(Teacher teacher) {
        teacherMapper.add(teacher);
    }

    @Override
    public Teacher selectById(Integer tno) {
        return teacherMapper.selectById(tno);
    }

    @Override
    public void update(Teacher teacher) {
        teacherMapper.update(teacher);
    }

    @Override
    public int deleteByIds(List<Integer> ids) {
        return teacherMapper.deleteByTnos(ids);
    }

    @Override
    public Teacher login(String username, String password) {
        return teacherMapper.selectByUsernameAndPassword(username,password);
    }

    @Override
    public Teacher selectByUsername(String username) {
        return teacherMapper.selectByUsername(username);
    }
}
